<?php
/**
 * @file featurecontroller.php
 * @author LinLin
 * @date 2016年7月22日 上午11:28:48
 * @brief 网站专题公共方法
 */
namespace haibao\cms\business\control;
use haibao\frame\data\query\Condition;
use haibao\cms\model\filter\ImageLibrary as ImageLibraryFilter;
use haibao\cms\model\filter\FeaturePublish as FeaturePublishFilter;
use haibao\cms\model\filter\FeatureDefine as FeatureDefineFilter;
use haibao\cms\model\filter\FeatureSerial as FeatureSerialFilter;
use haibao\cms\model\data\FeaturePublish as FeatureModel;
use haibao\frame\data\query\Pager;

class FeatureController extends \haibao\cms\business\control\Base{
    
    private static $pager;
    
    public static $featureSerial  = array(
        //stars
   		1383=>array(
	       'ChannelName'=>'明星/风潮','SerialIds'=>array(
   				39=>array('SerialName'=>'报尚名来','SerialUrl'=>'/featurelist/133/26/'),
   				42=>array('SerialName'=>'摩范先生','SerialUrl'=>'/featurelist/10506/226/'),
   				40=>array('SerialName'=>'潮我看齐','SerialUrl'=>'/featurelist/129/27/'),
   				22=>array('SerialName'=>'剧好看','SerialUrl'=>'/tvplay-list/'),
    			31=>array('SerialName'=>'红毯点播台','SerialUrl'=>'/redcarpetradio-list/'),
	       )
   		),
        //fashion
        310=>array('ChannelName'=>'时装/品牌','SerialIds'=>array(
            21=>array('SerialName'=>'摩豆','SerialUrl'=>'/modou-list/'),
            36=>array('SerialName'=>'搭配速成班','SerialUrl'=>'/fashionmatch-list/'),
            43=>array('SerialName'=>'恋物趣','SerialUrl'=>'/accessory-list/'),
            29=>array('SerialName'=>'明星珠宝个人Show','SerialUrl'=>'/jewelshow-list/'),
        )),
        //beauty
        24=>array('ChannelName'=>'美容/彩妆','SerialIds'=>array(
            35=>array('SerialName'=>'美容BANG','SerialUrl'=>'/featurelist/133/26/'),
            44=>array('SerialName'=>'街拍时妆','SerialUrl'=>''),
        	38=>array('SerialName'=>'新品见报','SerialUrl'=>'/featurelist/132/4/'),
            37=>array('SerialName'=>'海报口碑测评','SerialUrl'=>'/featurelist/152/1/'),
        )),
        //others
        'other'=>array('ChannelName'=>'直播/策划','SerialIds'=>array(
            4=>array('ClassName'=>'时装周','ClassUrl'=>'/featureflow/4/'),
            9=>array('ClassName'=>'秀场直播','ClassUrl'=>'/featureflow/9/'),
            10=>array('ClassName'=>'品牌定制','ClassUrl'=>'/featureflow/10/')
        )),
    );
    
    public static $featureDescMatch = array(
        39=>'海报时尚网每期为你邀请一位时尚明星，近距离感受明星真相，这里有你想看的明星资讯、想听的圈内故事、想知道的独家保养秘辛，一起分享明星的兴趣爱好，关注TA的时尚态度，探秘TA的美搭宝典，偷师TA的美妆秘籍。尽在《报尚名来》。',//报尚名来
        40=>'从T台到街头，不是模特也能做ICON，海报时尚网明星街拍支招，用最简单的元素穿出最时尚的自我风格。',//潮我看齐
        42=>'这里集合了时下最火的鲜肉、大叔，总有一款你的男神在这里。',//摩范先生
        37=>'海报时尚网王牌评测栏目，最应季的主题，最专业的视角，真实、全面评测6-8款口碑产品！每期一位业界专家老师坐镇，解答网友的护肤、彩妆问题，并邀请美妆届达人、海报Girls们一同加入口碑测评！',//海报口碑测评
        38=>'精准的根据当月最热的美妆需求进行美妆资讯的普及以及美妆新品的推荐，并且作为年底海报时尚网美妆大奖【尚妆之选】的数据依托，通过专家老师的建议为网友推荐最合适他们的美妆新品。',//Top新品见报
        41=>'收录最火爆的当红名流造型，每期选取一位当红时尚Icon，以人物为切入点进行造型的全面解读。让网友能够全面解读到偶像的妆发打造方法。同时包含专业级的点评以及视频教学，亲授给你妆容打造技法。',//美丽志
    );
    
    public static $featureLogo = array(
        20,21,22,29,31,35,37,38,39,40,42,43,44,46
    );
    
    public static $exclusiveSerial = array(
        'stars'=>array(
            'exclusive'=>array(22,31),//剧好看  红毯点播台
            'column'=>array()
        ),
        'fashion'=>array(
            'exclusive'=>array(21,36,43),//摩豆  搭配速成班  恋舞趣
            'column'=>array(12204)//报君潮流眼
        ),
        'beauty'=>array(
            'exclusive'=>array(35,44,37,38,45),//美容BANG 街拍时妆  海报口碑评测 新品见报  报告老师
            'column'=>array()
        ),
        'jewelrywatch'=>array(
            'exclusive'=>array(29,20),//明星珠宝个人秀  每周必buy
            'column'=>array()
        )
    );
    
    /**
     * 首页根据频道获取频道下最新的2个专题
     * @param : $classId 专题类别  （1潮流，2美妆，3明星,4时装周，5品牌）  如果改频道下没有，则查询时装频道
     * @param : $limit 返回个数，默认2
     */
    public static function getNewFeatureByChannelForIndex($classId=FeatureModel::CLASS_FASHION_WEEK,$limit=2,$isPage=false,$page=1,$serialId = null,$columnId = null){
        $featureFilter = new FeaturePublishFilter;
        $imageLibraryFilter = new ImageLibraryFilter();
        $featureFilter->order(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_LIST_TIME,false);
        $featureFilter->select(array(
            FeaturePublishFilter::CONDITION_FIELD_NAME_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_URL,
            FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_NAME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_COLUMN_ID
        ));
    
        $imageLibraryFilter->select(array(
            ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
        ));
    
        $defineFilter = new \haibao\cms\model\filter\FeatureDefine();
        $defineFilter->select(array(
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_COLUMN_ID,
        ));
        $featureFilter->innerJoin(
            $defineFilter,
            null,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
            false
        );
         
        $featureSerial = new \haibao\cms\model\filter\FeatureSerial();
        $featureSerial->select(array(
            $featureSerial::CONDITION_FIELD_NAME_ID,
            $featureSerial::CONDITION_FIELD_NAME_SERIAL_NAME
        ));
         
        $featureFilter->leftJoin(
            $featureSerial,
            $defineFilter,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
            \haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL,
            false
        );
        $featureFilter->leftJoin($imageLibraryFilter,$featureFilter,FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,FeaturePublishFilter::CONDITION_FIELD_NAME_IMAGE,false);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_H5, Condition::CONDITION_EQUAL, 0);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_LIST, Condition::CONDITION_EQUAL, 1);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_URL, Condition::CONDITION_NOT_LIKE, '%/brand/%');
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, FeatureModel::STATUS_PUBLISH);
        if($classId){
            $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_CLASS_ID,CONDITION::CONDITION_EQUAL,$classId);
        }
        if($serialId && $columnId){
            $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_ID, Condition::CONDITION_OR,array(
                new Condition(FeaturePublishFilter::CONDITION_FIELD_NAME_SERIAL_ID,Condition::CONDITION_IN,$serialId),
                new Condition(FeaturePublishFilter::CONDITION_FIELD_NAME_COLUMN_ID,Condition::CONDITION_IN,$columnId)
            ));
             
            $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,Condition::CONDITION_OR,array(
                new Condition(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,Condition::CONDITION_IN,$serialId),
                new Condition(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_COLUMN_ID,Condition::CONDITION_IN,$columnId),
            ));
             
        }elseif($serialId && !$columnId){
            if(is_array($serialId)){
                $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,Condition::CONDITION_IN,$serialId);
            }else{
                $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,Condition::CONDITION_EQUAL,$serialId);
            }
        }elseif(!$serialId && $columnId){
            if(is_array($columnId)){
                $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_COLUMN_ID,Condition::CONDITION_IN,$columnId);
            }else{
                $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_COLUMN_ID,Condition::CONDITION_EQUAL,$columnId);
            }
        }
    
        if($isPage){
            $featureFilter->setPager(new Pager($limit,$page));
        }else{
            $featureFilter->limit($limit);
        }
         
        $data = new \haibao\cms\data\FeaturePublish();
        $data->setConfig( \haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS );
        $result = $data->getAll($featureFilter);
        if($isPage){
            $pager = $featureFilter->getPager();
            return array($result,$pager);
        }
        foreach($result as $key=>$val){
            $result[$key]->FeatureName = $val->FeatureDefine->FeatureName;
        }
        return $result;
    }
    
    
    /**
     * 根据频道获取频道下最新的2个专题
     * @param : $classId 专题类别  （1潮流，2美妆，3明星,4时装周，5品牌）  如果改频道下没有，则查询时装频道
     * @param : $limit 返回个数，默认2
     */
    public static function getFeatureByChannel($classId=FeatureModel::CLASS_FASHION_WEEK,$limit=2,$isPage=false,$page=1,$serialId = null){
        $featureFilter = new FeaturePublishFilter;
        $imageLibraryFilter = new ImageLibraryFilter();
        $featureFilter->order(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_LIST_TIME,false);
        $featureFilter->select(array(
            FeaturePublishFilter::CONDITION_FIELD_NAME_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_URL,
            FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_NAME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME,
        ));
         
        $defineFilter = new \haibao\cms\model\filter\FeatureDefine();
        $defineFilter->select(array(
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
        ));
        $featureFilter->innerJoin(
            $defineFilter,
            null,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
            false
        );
         
        $imageLibraryFilter->select(array(
            ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
        ));
         
        $featureFilter->leftJoin($imageLibraryFilter,$featureFilter,FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,FeaturePublishFilter::CONDITION_FIELD_NAME_IMAGE,false);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_H5, Condition::CONDITION_EQUAL, 0);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_LIST, Condition::CONDITION_EQUAL, 1);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, FeatureModel::STATUS_PUBLISH);
        if($classId){
            $defineFilter->where(
                \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_CLASS_ID,
                Condition::CONDITION_EQUAL,
                $classId
            );
        }
        if($serialId){
            if(is_array($serialId)){
                $defineFilter->where(
                    \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
                    Condition::CONDITION_IN,
                    $serialId
                );
            }else{
                $defineFilter->where(
                    \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
                    Condition::CONDITION_EQUAL,
                    $serialId
                );
            }
        }
        if($isPage){
            $featureFilter->setPager(new Pager($limit,$page));
        }else{
        	$featureFilter->limit($limit);
        }
         
        $existFilter =  new \haibao\cms\model\filter\FeatureTag();
        $existFilter->select(array(\haibao\cms\model\filter\FeatureTag::CONDITION_FIELD_NAME_ID));
        $existFilter->where(
            \haibao\cms\model\filter\FeatureTag::CONDITION_FIELD_NAME_TAG_ID,
            Condition::CONDITION_EQUAL,
            \haibao\cms\model\data\FeatureTag::JING_PIN_LAN_MU_ID
        );
        $existFilter->where(
            \haibao\cms\model\filter\FeatureTag::CONDITION_FIELD_NAME_FEATURE_ID,
            Condition::CONDITION_EQUAL,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_ID,
            $existFilter,
            $featureFilter
        );
        $featureFilter->where(
            \haibao\cms\model\filter\FeatureTag::CONDITION_FIELD_NAME_ID,
            Condition::CONDITION_NOTEXISTS,
            $existFilter
        );
         
        $data = new \haibao\cms\data\FeaturePublish();
        $data->setConfig( \haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS );
        $result = $data->getAll($featureFilter);
        if($isPage){
            $pager = $featureFilter->getPager();
            return array($result,$pager);
        }
        foreach($result as $key=>$val){
            $result[$key]->FeatureName = $val->FeatureDefine->FeatureName;
        }
        return $result;
    }
    
    
    public static function getFeaturelist($columnId=0,$limit=3,$page=1,$isKillBrand=true){
        $result = self::getFeatureByColumnId($columnId,$limit,$page,$isKillBrand);
        return array($result,self::$pager);
    }
    
    /**
     * 通过栏目ID获取专题
     * @param number $columnId
     * @param number $limit
     * @param number $page
     * @param string $isKillBrand
     */
    public static function getFeatureByColumnId($columnId=0,$limit=3,$page=1,$isKillBrand=true){
        $featureFilter = new FeaturePublishFilter;
        $imageLibraryFilter = new ImageLibraryFilter();
        $featureFilter->setPager(new Pager($limit,$page));
        $featureFilter->order(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_LIST_TIME,false);
        $featureFilter->select(array(
            FeaturePublishFilter::CONDITION_FIELD_NAME_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_DESCRIPTION,
            FeaturePublishFilter::CONDITION_FIELD_NAME_URL,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_NAME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME
        ));
         
        $defineFilter = new \haibao\cms\model\filter\FeatureDefine();
        $defineFilter->select(array(
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID
        ));
        $featureFilter->innerJoin(
            $defineFilter,
            null,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
            false
        );
         
        $imageLibraryFilter->select(array(
            ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
        ));
        $featureFilter->leftJoin($imageLibraryFilter,$featureFilter,FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,FeaturePublishFilter::CONDITION_FIELD_NAME_IMAGE,false);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_H5, Condition::CONDITION_EQUAL, 0);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, FeatureModel::STATUS_PUBLISH);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_LIST, Condition::CONDITION_EQUAL, 1);
        if($columnId != -1){
            if($isKillBrand){
                $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_URL, Condition::CONDITION_NOT_LIKE, '%/brand/%');
            }
            $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_COLUMN_ID,Condition::CONDITION_EQUAL, $columnId);
        }
         
        $existFilter =  new \haibao\cms\model\filter\FeatureTag();
        $existFilter->select(array(\haibao\cms\model\filter\FeatureTag::CONDITION_FIELD_NAME_ID));
        $existFilter->where(
            \haibao\cms\model\filter\FeatureTag::CONDITION_FIELD_NAME_TAG_ID,
            Condition::CONDITION_EQUAL,
            \haibao\cms\model\data\FeatureTag::JING_PIN_LAN_MU_ID
        );
        $existFilter->where(
            \haibao\cms\model\filter\FeatureTag::CONDITION_FIELD_NAME_FEATURE_ID,
            Condition::CONDITION_EQUAL,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_ID,
            $existFilter,
            $featureFilter
        );
        $featureFilter->where(
            \haibao\cms\model\filter\FeatureTag::CONDITION_FIELD_NAME_ID,
            Condition::CONDITION_NOTEXISTS,
            $existFilter
        );
         
        $data = new \haibao\cms\data\FeaturePublish();
        $result = $data->getAll($featureFilter);
        self::$pager = $featureFilter->getPager();
        foreach($result as $key=>$val){
            $result[$key]->FeatureName = $val->FeatureDefine->FeatureName;
        }
        return $result;
    }
    
    /**
     * 通过系列ID获取专题
     * @param unknown $serialId
     * @param number $limit
     */
    public static function getserialInfoById($serialId,$limit=1){
        $featurePublishFilter = new \haibao\cms\model\filter\FeaturePublish();
        $featurePublishFilter->select(array(
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_URL,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_CREATE_TIME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_PUBLISH_TIME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_PICTURE_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_H5,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_COLUMN_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_SERIAL_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_LIST_TIME
        ));
        $imageLibraryFilter = new ImageLibraryFilter();
        $imageLibraryFilter->select(array(
            ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
        ));
        $featurePublishFilter->leftJoin($imageLibraryFilter,null,FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,FeaturePublishFilter::CONDITION_FIELD_NAME_IMAGE,false);
        $featurePublishFilter->order(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_LIST_TIME,false);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\FeaturePublish::STATUS_PUBLISH);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_H5,Condition::CONDITION_EQUAL,0);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_LIST,Condition::CONDITION_EQUAL,1);
        $featurePublishFilter->limit($limit);
    
        $defineFilter = new \haibao\cms\model\filter\FeatureDefine();
        $defineFilter->select(array(
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
        ));
        $featurePublishFilter->innerJoin(
            $defineFilter,
            null,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
            false
        );
        $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID, Condition::CONDITION_EQUAL, $serialId);
    
        $featureList = \haibao\cms\business\FeaturePublish::searchFeature($featurePublishFilter);
        if($featureList){
            foreach($featureList as $key=>$val){
                $featureList[$key]->FeatureName = $val->FeatureDefine->FeatureName;
            }
        }
        return $featureList;
    }
    
    
    /**
     * 获取具体数据(品牌库专题)
     * @param 固定ID $brandsTagId
     * @param 类别名称 $name
     * @param 去重复 $brandsTagArr
     * @return Ambigous <NULL, unknown>
     */
    public static function getBrandSerialInfoById($brandsTagId,$name,$brandsTagArr){
         
        $featurePublishFilter = new \haibao\cms\model\filter\FeaturePublish();
         
        $featurePublishFilter->select(array(
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_ISSUE,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_URL,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_STATUS,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_CREATE_TIME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_PUBLISH_TIME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_PICTURE_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_H5,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_COLUMN_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_SERIAL_ID
        ));
        $featurePublishFilter->order(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_PUBLISH_TIME,false);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\FeaturePublish::STATUS_PUBLISH);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_H5,Condition::CONDITION_EQUAL,0);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_LIST,Condition::CONDITION_EQUAL,1);
         
        $defineFilter = new \haibao\cms\model\filter\FeatureDefine();
        $defineFilter->select(array(
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
        ));
        $featurePublishFilter->innerJoin(
            $defineFilter,
            null,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
            false
        );
         
        $serialFiler = new \haibao\cms\model\filter\FeatureSerial();
        $serialFiler->select(array(
            \haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_SERIAL_NAME,
            \haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_ID,
        ));
        if($brandsTagId){
            if($name == "serial"){
                $serialFiler->where(\haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_ID,Condition::CONDITION_EQUAL,$brandsTagId);
                /* $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_COLUMN_ID,Condition::CONDITION_NOTEQUAL,$brandsTagArr[2]);
                 $featurePublishFilter->leftJoin(
                 $serialFiler,
                 null,
                 \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_SERIAL_ID,
                 \haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_ID,
                 \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_SERIAL,
                 false
                 ); */
                 
                $featurePublishFilter->leftJoin(
                    $serialFiler,
                    $defineFilter,
                    \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
                    \haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_ID,
                    \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL,
                    false
                );
                 
            }elseif ($name == "ColumnId"){
                //$featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_COLUMN_ID,Condition::CONDITION_EQUAL,$brandsTagId);
                //$featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_SERIAL_ID,Condition::CONDITION_NOTEQUAL,$brandsTagArr[0]);
                //$featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_SERIAL_ID,Condition::CONDITION_NOTEQUAL,$brandsTagArr[1]);
                $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_COLUMN_ID,Condition::CONDITION_EQUAL,$brandsTagId);
                $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,Condition::CONDITION_NOTEQUAL,$brandsTagArr[0]);
                $defineFilter->where(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,Condition::CONDITION_NOTEQUAL,$brandsTagArr[1]);
            }
        }
         
        $featurePublishFilter->limit(1);
        $featureList = \haibao\cms\business\FeaturePublish::searchFeature($featurePublishFilter,true);
        if($featureList){
            $featureList->FeatureName = $featureList->FeatureDefine->FeatureName;
        }
        return $featureList;
    }
    
    /**
     * 明星库专题获取
     * @param unknown $brandsTagId
     */
    
    public static function getStarSerialInfoById($brandsTagId){
        $featurePublishFilter = new \haibao\cms\model\filter\FeaturePublish();
        	
        $featurePublishFilter->select(array(
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_ISSUE,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_URL,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_STATUS,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_CREATE_TIME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_PUBLISH_TIME,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_PICTURE_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_H5,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_COLUMN_ID,
        ));
        $featurePublishFilter->order(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_PUBLISH_TIME,false);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\FeaturePublish::STATUS_PUBLISH);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_H5,Condition::CONDITION_EQUAL,0);
        $featurePublishFilter->where(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_IS_LIST,Condition::CONDITION_EQUAL,1);
    
        $serialFiler = new \haibao\cms\model\filter\FeatureSerial();
        $serialFiler->select(array(
            \haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_SERIAL_NAME,
            \haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_ID,
        ));
        if($brandsTagId){
            $serialFiler->where(\haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_ID,Condition::CONDITION_EQUAL,$brandsTagId);
        }
    
        $defineFilter = new \haibao\cms\model\filter\FeatureDefine();
        $defineFilter->select(array(
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
        ));
        $featurePublishFilter->innerJoin(
            $defineFilter,
            null,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
            false
        );
    
        $featurePublishFilter->leftJoin(
            $serialFiler,
            $defineFilter,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
            \haibao\cms\model\filter\FeatureSerial::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL,
            false
        );
        $featurePublishFilter->limit(1);
        $featureList = \haibao\cms\business\FeaturePublish::searchFeature($featurePublishFilter,true);
        if(isset($featureList) && $featureList){
            $featureList->FeatureName = $featureList->FeatureDefine->FeatureName;
        }
        return $featureList;
    }
    
    /**
     * 手机专题列表
     * @param unknown $page
     * @param number $limit
     */
    public static function getMobileFeatureList($page,$limit=4){
        $featureFilter = new FeaturePublishFilter;
        $imageLibraryFilter = new ImageLibraryFilter();
        $featureFilter->setPager(new Pager($limit,$page));
        $featureFilter->order(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_LIST_TIME,false);
        $featureFilter->select(array(
            FeaturePublishFilter::CONDITION_FIELD_NAME_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_DESCRIPTION,
            FeaturePublishFilter::CONDITION_FIELD_NAME_URL,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_NAME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME
        ));
    
        $imageLibraryFilter->select(array(
            ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
        ));
        $featureFilter->leftJoin($imageLibraryFilter,$featureFilter,FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,FeaturePublishFilter::CONDITION_FIELD_NAME_IMAGE,false);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_H5, Condition::CONDITION_EQUAL, 1);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME, Condition::CONDITION_GREATER, 0);
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID, Condition::CONDITION_NOTEQUAL, '');
        $featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, FeatureModel::STATUS_PUBLISH);
    
        $defineFilter = new \haibao\cms\model\filter\FeatureDefine();
        $defineFilter->select(array(
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID
        ));
        $featureFilter->innerJoin(
            $defineFilter,
            null,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
            false
        );
    
        $data = new \haibao\cms\data\FeaturePublish();
        $result = $data->getAll($featureFilter);
        $pager = $featureFilter->getPager();
        $pageCount = $pager->getPageCount();
        if($page > $pageCount){
            return array();
        }else{
            foreach($result as $key=>$val){
                $result[$key]->FeatureName = $val->FeatureDefine->FeatureName;
            }
            return $result;
        }
    }
    
    /**
     * 获取专题数据
     */
    public static function getFeatureListById($featureId,$isH5=0){
    	$featureFilter = new FeaturePublishFilter;
    	$imageLibraryFilter = new ImageLibraryFilter();
    	$featureFilter->select(array(
    			FeaturePublishFilter::CONDITION_FIELD_NAME_ID,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_URL,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_NAME,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
    	));
    	
    	$imageLibraryFilter->select(array(
    			ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
    	));
    	
    	/* $defineFilter = new \haibao\cms\model\filter\FeatureDefine();
    	$defineFilter->select(array(
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_COLUMN_ID,
    	));
    	$featureFilter->innerJoin(
    			$defineFilter,
    			null,
    			\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
    			\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
    			false
    	); */
    	 
    	$featureFilter->leftJoin($imageLibraryFilter,$featureFilter,FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,FeaturePublishFilter::CONDITION_FIELD_NAME_IMAGE,false);
    	$featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_H5, Condition::CONDITION_EQUAL, $isH5);
    	//$featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_LIST, Condition::CONDITION_EQUAL, 1);
    	$featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_URL, Condition::CONDITION_NOT_LIKE, '%/brand/%');
    	$featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, FeatureModel::STATUS_PUBLISH);
    	$featureFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID, Condition::CONDITION_IN, $featureId);
    	 
    	$data = new \haibao\cms\data\FeaturePublish();
    	$data->setConfig( \haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS );
    	$result = $data->getAll($featureFilter);
    	$featureList = array();
    	foreach($result as $key=>$val){
    		$featureList[$val->FeatureDefineId] = $val;
    	}
    	return $featureList;
    }
    
    
    /**
     * 查询最新的6个系列
     * $channel 频道Id
     * $serialIdArr 当前频道系列数组
     */
    public static function getFeatureGroupBySerialId($serialIdArr = array(),$limit = 6,$width=340,$height=256){
        $featureList = array();
        $featurePublish = new \haibao\cms\data\FeaturePublish();
        $featureList = $featurePublish->getFeatureGroupBySerialId($serialIdArr,$limit);
        if($featureList){
           foreach($featureList as $key=>$val){
               $featureList[$key]['Filename'] = self::getImageLink($val['Filename'],$width,$height);
           } 
        }
        return $featureList;
    }
    
    public static function getFeatureGroupByClassId($classIdArr = array(),$limit = 3,$width=340,$height=256){
        $featureList = array();
        $featurePublish = new \haibao\cms\data\FeaturePublish();
        $featureList = $featurePublish->getFeatureGroupByClassId($classIdArr,$limit);
        if($featureList){
            foreach($featureList as $key=>$val){
                $featureList[$key]['Filename'] = self::getImageLink($val['Filename'],$width,$height);
            }
        }
        return $featureList;
    }
    
    /**
     * 根据系列获取最新的专题
     */
    public static function getNewFeatureBySerialId($serailId,$limit = 6,$currentPage = 1,$isReturnPage = false){
    	$featureDefineFilter = new FeatureDefineFilter;
    	$featurePublishFilter = new FeaturePublishFilter;
    	$imageLibraryFilter = new ImageLibraryFilter;
    	
    	$featureDefineFilter->select(array(
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
    			\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_COLUMN_ID,
    	));
    	
    	$featurePublishFilter->select(array(
    			FeaturePublishFilter::CONDITION_FIELD_NAME_ID,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_URL,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_NAME,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME,
    			FeaturePublishFilter::CONDITION_FIELD_NAME_COLUMN_ID,
    	        FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME,
    	));
    	
    	$imageLibraryFilter->select(array(
    	    ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
    	));
    	$featureDefineFilter->innerjoin(
    	    $featurePublishFilter,
    	    null,
    	    \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
    	    \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
    	    \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_PUBLISHES,
    	    false
    	);
 
		$featureDefineFilter->innerjoin($imageLibraryFilter,$featurePublishFilter,FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,FeaturePublishFilter::CONDITION_FIELD_NAME_IMAGE,false);
    	
    	$featurePublishFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_H5, Condition::CONDITION_EQUAL, 0);
    	$featurePublishFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_LIST, Condition::CONDITION_EQUAL, 1);
    	$featurePublishFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, FeatureModel::STATUS_PUBLISH);
    	$featureDefineFilter->order(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,false);
    	if(is_array($serailId)){
    		$featureDefineFilter->where(FeatureDefineFilter::CONDITION_FIELD_NAME_SERIAL_ID, Condition::CONDITION_IN, $serailId);
    	}else{
    		$featureDefineFilter->where(FeatureDefineFilter::CONDITION_FIELD_NAME_SERIAL_ID, Condition::CONDITION_EQUAL, $serailId);
    	}
        
    	if($isReturnPage){
    	    $featureDefineFilter->setPager(new Pager($limit,$currentPage));
    	}else{
    	    $featureDefineFilter->limit($limit);
    	}
    	$data = new \haibao\cms\data\FeaturePublish();
    	$data->setConfig( \haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS );
    	$featureList = $data->getAll($featureDefineFilter);
    	$featureListArr = array();
    	
    	$featureImageUrl = self::getImageUrlBySerials();
    	// 获取serialTree -> private array(key=>value)
    	foreach($featureList as $key=>$feature){
    		$temp = array();
    		$temp['Id'] = $feature->Id;
    		$temp['FeaturePublishId'] = $feature->FeaturePublishes->Id;
    		$temp['FeatureName'] = $feature->FeatureName;
    		$temp['SerialId'] = $feature->SerialId;
    		$temp['Description'] = $feature->Description;
    		$temp['ImageUrl'] = self::getImageLink($feature->FeaturePublishes->Image->Filename,340,256);
    		$temp['FeatureUrl'] = $feature->FeaturePublishes->Url;
    		$temp['ListTime'] = $feature->FeaturePublishes->ListTime->format('Y-m-d');
     		$temp['SerialNameById'] = isset($featureImageUrl[$feature->SerialId]['SerialName'])&&$featureImageUrl[$feature->SerialId]['SerialName'] ?$featureImageUrl[$feature->SerialId]['SerialName'] :'';
     		$temp['SerialImageUrl'] = isset($featureImageUrl[$feature->SerialId]['SerialLogoUrl'])&&$featureImageUrl[$feature->SerialId]['SerialLogoUrl'] ?self::getImageLink($featureImageUrl[$feature->SerialId]['SerialLogoUrl'],100,100) :'';
     		$temp['SerialDesc'] = isset($featureImageUrl[$feature->SerialId]['SerialDesc'])&&$featureImageUrl[$feature->SerialId]['SerialDesc'] ?$featureImageUrl[$feature->SerialId]['SerialDesc'] :'';
    		array_push($featureListArr,$temp);
    	}
    	if($isReturnPage){
    	    return array($featureListArr,$featureDefineFilter->getPager());
    	}else{
    	    return $featureListArr;
    	}
    	
    }
    
    /**
     * 根据classid获取最新的专题
     */
    public static function getNewFeatureByClassId($classId,$limit = 6,$currentPage = 1,$isReturnPage = false){
        $featureDefineFilter = new FeatureDefineFilter;
        $featurePublishFilter = new FeaturePublishFilter;
        $imageLibraryFilter = new ImageLibraryFilter;
         
        $featureDefineFilter->select(array(
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_DESCRIPTION,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_SERIAL_ID,
        ));
         
        $featurePublishFilter->select(array(
            FeaturePublishFilter::CONDITION_FIELD_NAME_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,
            FeaturePublishFilter::CONDITION_FIELD_NAME_URL,
            FeaturePublishFilter::CONDITION_FIELD_NAME_FEATURE_NAME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
            FeaturePublishFilter::CONDITION_FIELD_NAME_LIST_TIME,
        ));
         
        $imageLibraryFilter->select(array(
            ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
        ));
        $featureDefineFilter->innerjoin(
            $featurePublishFilter,
            null,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
            \haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
            \haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_PUBLISHES,
            false
        );
        
        $featureDefineFilter->innerjoin($imageLibraryFilter,$featurePublishFilter,FeaturePublishFilter::CONDITION_FIELD_NAME_PICTURE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,FeaturePublishFilter::CONDITION_FIELD_NAME_IMAGE,false);
         
        //$featurePublishFilter->order(\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_LIST_TIME,false);
        $featureDefineFilter->order(\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,false);
        $featurePublishFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_H5, Condition::CONDITION_EQUAL, 0);
        $featurePublishFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_IS_LIST, Condition::CONDITION_EQUAL, 1);
        $featurePublishFilter->where(FeaturePublishFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, FeatureModel::STATUS_PUBLISH);
        $featureDefineFilter->where(FeatureDefineFilter::CONDITION_FIELD_NAME_CLASS_ID, Condition::CONDITION_EQUAL, $classId);
    
        if($isReturnPage){
            $featureDefineFilter->setPager(new Pager($limit,$currentPage));
        }else{
            $featureDefineFilter->limit($limit);
        }
        
        $data = new \haibao\cms\data\FeaturePublish();
        $data->setConfig( \haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_CMS );
        $featureList = $data->getAll($featureDefineFilter);
        $featureListArr = array();
         
        foreach($featureList as $key=>$feature){
            $temp = array();
            $temp['Id'] = $feature->Id;
            $temp['FeaturePublishId'] = $feature->FeaturePublishes->Id;
            $temp['FeatureName'] = $feature->FeatureName;
            $temp['SerialId'] = $feature->SerialId;
            $temp['Description'] = $feature->Description;
            $temp['ImageUrl'] = self::getImageLink($feature->FeaturePublishes->Image->Filename,340,256);
            $temp['FeatureUrl'] = $feature->FeaturePublishes->Url;
            $temp['ListTime'] = $feature->FeaturePublishes->ListTime->format('Y-m-d');
            $temp['SerialNameById'] = '';
            $temp['SerialImageUrl'] = '';
            $temp['SerialDesc'] = '';
            array_push($featureListArr,$temp);
        }
        if($isReturnPage){
            return array($featureListArr,$featureDefineFilter->getPager());
        }else{
            return $featureListArr;
        }
        
    }
    
    public static function getSerialInfo($serialId){
    	
    	$filter = new FeatureSerialFilter;
    	$filter->select(array(
    			FeatureSerialFilter::CONDITION_FIELD_NAME_ID,
    			FeatureSerialFilter::CONDITION_FIELD_NAME_SERIAL_NAME,
    			FeatureSerialFilter::CONDITION_FIELD_NAME_SERIAL_DESC,
    	        FeatureSerialFilter::CONDITION_FIELD_NAME_SERIAL_LOGOURL
    	));
    	if(is_array($serialId)){
    		$filter->where(FeatureSerialFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_IN,$serialId);
    	}else{
    		$filter->where(FeatureSerialFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_EQUAL,$serialId);
    	}
    	$data = new \haibao\cms\data\FeaturePublish();
    	$list = $data->getAll($filter);
    	$featureSerialArr = array();
    	foreach($list as $val){
    		$temp = array('SerialName'=>$val->SerialName,'SerialDesc'=>$val->SerialDesc,
    		    'SerialLogoUrlLibr'=> $val->SerialLogoUrl,
    		    'SerialLogoUrlSmall'=> !empty($val->SerialLogoUrl) ? self::getImageLink($val->SerialLogoUrl,100,100) : '',
    		    'SerialLogoUrlBig'=> !empty($val->SerialLogoUrl) ? self::getImageLink($val->SerialLogoUrl,300,300) : '',
    		);
    		$featureSerialArr[$val->Id] = $temp;
    	}
    	return $featureSerialArr;
    }
    
    /**
     * 获取专题系列数组
     */
    public static function getFeatureSerialArray(){
        $featureSerialArr = array();
        $featureCache = new \haibao\cms\data\FeatureSerial();
        $featureSerialArr = $featureCache->getCategoryTree();
        if($featureSerialArr){
            foreach($featureSerialArr as $key=>$val){
                if($val['SerialName'] == '直播/策划'){
                    $featureSerialArr[$key]['children'][] = array('Id'=>52,'SerialName'=>'时装周','SerialParent'=>$key,'SortInParent'=>1);
                    $featureSerialArr[$key]['children'][] = array('Id'=>53,'SerialName'=>'秀场直播','SerialParent'=>$key,'SortInParent'=>2);
                    $featureSerialArr[$key]['children'][] = array('Id'=>54,'SerialName'=>'特别策划','SerialParent'=>$key,'SortInParent'=>3);
                }
                if(isset($val['children'])){
                    foreach($val['children'] as $k => $v) {
                        if($v['SortInParent'] == '' || $v['SortInParent'] == null || $v['SortInParent'] == 0){
                            $featureSerialArr[$key]['children'][$k]['SortInParent'] = 1000;
                        }
                    }
                }
            }
            foreach($featureSerialArr as $parentId=>$feature) {
                $orders = array();
                if(isset($feature['children'])){
                    foreach($feature['children'] as $k => $v) {
                        $orders[$k] = $v['SortInParent'];
                    }
                    array_multisort($orders, SORT_ASC,$featureSerialArr[$parentId]['children']);
                }
            }
            $temp = array();
            foreach($featureSerialArr as $key=>$val){
                if($val['SerialName'] == '明星/风潮' || $val['SerialName'] == '时装/品牌' || $val['SerialName'] == '美容/彩妆' || $val['SerialName'] == '直播/策划'){
                    $temp[] = $featureSerialArr[$key];
                }            
            }
            if(empty($temp)){
                $temp = $featureSerialArr;
            }
        }
        return $temp;
    }
    
    /**
     * 获取专题所有对应的图片
     */
    public static function getImageUrlBySerials(){
    	$featureImage = array();
    	$featureCache = new \haibao\cms\data\FeatureSerial();
    	$featureSerialArr = $featureCache->getCategoryTree();
    	
    	if($featureSerialArr){
    		foreach ($featureSerialArr as $featureSerialOne){
    			$featureImage[$featureSerialOne['Id']]['SerialLogoUrl'] = $featureSerialOne['SerialLogoUrl'];
    			$featureImage[$featureSerialOne['Id']]['SerialName'] = $featureSerialOne['SerialName'];
    			$featureImage[$featureSerialOne['Id']]['SerialDesc'] = $featureSerialOne['SerialDesc'];
    			
    			if(isset($featureSerialOne['children'])){
    				foreach($featureSerialOne['children'] as $k => $v) {
    					$temp['SerialLogoUrl'] = $v['SerialLogoUrl'];
    					$temp['SerialName'] = $v['SerialName'];
    					$temp['SerialDesc'] = $v['SerialDesc'];
    					$featureImage[$v['Id']] = $temp;
    				}
    			}
    			
    		}
    		
    	}
    	return $featureImage;
    	
    }
    
} 